<template>
  <div class="m-login-container">
    <el-row class="m-main-header-search" justify="space-between">
      <el-form hide-required-asterisk :inline="true" ref="refForm">
        <el-row>
          <el-form-item prop="order_sn" label="审核状态">
            <el-select
              v-model="refFormData.audit"
              size="small"
              filterable
              reserve-keyword
              @change="handleSearch"
              placeholder="请选择状态"
            >
              <el-option
                v-for="item in auditList"
                :key="item.id"
                :value="item.id"
                :label="item.name"
              />
            </el-select>
          </el-form-item>
          <!-- <el-button @click="handleSearch()" type="primary" size="small">
          查询
        </el-button> -->
        </el-row>
      </el-form>
      <el-button
        :disabled="!this.selectedIds || !this.selectedIds.length"
        @click="handleAudit()"
        class="audit-btn"
        size="small"
        icon="el-icon-circle-check"
      >
        审核
      </el-button>
    </el-row>
    <div class="m-main-content-body">
       <p class="contant-body-title">列表</p>
      <el-table
        v-loading="loading"
        :data="list"
        tooltip-effect="dark"
        class="table"
        :inline="false"
        stripe
        :header-cell-style="{
          'background-color': '#E5EEFF',
        }"
        ref="refAuditListTable"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" fixed width="55"> </el-table-column>

        <el-table-column
          prop="order_sn"
          label="订单编号"
          :autoFit="true"
          :fitHeader="true"
        >
        </el-table-column>
        <el-table-column
          prop="goods_sn"
          label="商品编号"
          :autoFit="true"
          :fitHeader="true"
        ></el-table-column>
        <el-table-column
          prop="goods_name"
          label="商品名"
          :autoFit="true"
          :fitHeader="true"
        ></el-table-column>
        <el-table-column
          prop="goods_region"
          label="商品地址"
          :autoFit="true"
          :fitHeader="true"
        ></el-table-column>
        <el-table-column
          prop="price"
          label="cod价格"
          :autoFit="true"
          :fitHeader="true"
        ></el-table-column>
        <el-table-column
          prop="user_name"
          label="用户名"
          :autoFit="true"
          :fitHeader="true"
        ></el-table-column>
        <!-- <el-table-column
        prop="price"
        label="cod价格"
        :autoFit="true"
        :fitHeader="true"
      ></el-table-column> -->
        <el-table-column
          prop="address"
          label="地址"
          :autoFit="true"
          :fitHeader="true"
        ></el-table-column>
        <el-table-column
          prop="ip"
          label="ip"
          :autoFit="true"
          :fitHeader="true"
        ></el-table-column>
        <el-table-column
          prop="ip_region"
          label="ip归属地"
          :autoFit="true"
          :fitHeader="true"
        ></el-table-column>
        <el-table-column
          prop="remarks"
          label="备注"
          :autoFit="true"
          :fitHeader="true"
        ></el-table-column>
        <el-table-column
          prop="biz_user_name"
          label="业务员名称"
          :autoFit="true"
          :fitHeader="true"
        ></el-table-column>
        <el-table-column
          prop="audit"
          label="审核状态"
          :autoFit="true"
          :fitHeader="true"
        >
          <template slot-scope="scope">
            {{ scope.row.audit | auditStatus }}
          </template>
        </el-table-column>
        <el-table-column
          prop="s_name"
          label="相似用户名"
          :autoFit="true"
          :fitHeader="true"
        ></el-table-column>
        <el-table-column
          prop="s_addr"
          label="地址雷同数量"
          :autoFit="true"
          :fitHeader="true"
        ></el-table-column>
        <el-table-column
          prop="s_phone"
          label="手机号雷同数量"
          :autoFit="true"
          :fitHeader="true"
        ></el-table-column>
        <el-table-column
          prop="s_ip"
          label="雷同数量"
          :autoFit="true"
          :fitHeader="true"
        ></el-table-column>
        <el-table-column
          prop="express_status"
          label="物流状态"
          :autoFit="true"
          :fitHeader="true"
        >
          <template slot-scope="scope">
            {{ scope.row.express_status | expressStatusName }}
          </template>
        </el-table-column>
        <el-table-column
          prop="express_no"
          label="物流单号"
          :autoFit="true"
          :fitHeader="true"
        >
        </el-table-column>
        <el-table-column
          prop="time"
          label="时间"
          :autoFit="true"
          :fitHeader="true"
        >
          <template slot-scope="scope">
            {{
              scope.row.time
                ? $moment(scope.row.time).format("YYYY/MM/DD HH:mm:ss")
                : "--"
            }}
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          @size-change="(val) => handlePageMetaChange(val, 'size')"
          @current-change="(val) => handlePageMetaChange(val, 'page')"
          :current-page="pageMeta.page"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="pageMeta.limit"
          layout="sizes, prev, next, jumper"
          :total="pageMeta.total"
        >
        </el-pagination>
      </div>
    </div>
    <dialog-set
      v-if="dislogSetVisible"
      @close="dislogSetVisible = false"
      :info="selectedIds"
      @getList="auditSuccess"
    ></dialog-set>
  </div>
</template>

<script>
import DialogSet from "./components/DialogSet";
import { auditList, getTagName, getExpressStatusName } from "./config/index";
export default {
  components: {
    DialogSet,
  },
  filters: {
    auditStatus: getTagName,
    expressStatusName: getExpressStatusName,
  },
  data() {
    return {
      list: [],
      loading: false,
      dislogSetVisible: false,
      refFormData: {
        audit: 0,
      },
      pageMeta: {
        page: 1,
        limit: 10,
        total: 1e10,
      },
      auditList,
      selectedIds: [],
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    /*
     * @Desc: 获取列表
     * @params: {String}
     * @return: {Object}
     */
    async getList() {
      this.loading = true;
      const { data } = await this.$api.audit.getList({
        ...this.pageMeta,
        page: this.pageMeta.page - 1,
        ...this.refFormData,
      });
      const { code, data: list } = data;
      if (code === 200) {
        this.list = list;
      }
      this.loading = false;
    },

    /*
     * @Desc:
     * @params: {String}
     * @return: {Object}
     */
    async handleSearch() {
      this.pageMeta.page = 1;
      this.getList();
    },

    /*
     * @Desc: 审核
     * @params: {String}
     * @return: {Object}
     */
    async handleAudit() {
      this.dislogSetVisible = true;
    },

    /*
     * @Desc: 审核成功回调
     * @params: {String}
     * @return: {Object}
     */
    async auditSuccess() {
      this.$refs.refAuditListTable.clearSelection();
      this.handleSearch();
    },

    /**
     * @Desc 分页
     * @params {String} val page/limit
     * @params {String} type  page/size
     * @return {Object}
     * */
    handlePageMetaChange(val, type = "size") {
      this.pageMeta[type === "size" ? "limit" : "page"] = val;
      this.getList();
    },

    /*
     * @Desc: 多选
     * @params: {String}
     * @return: {Object}
     */
    handleSelectionChange(v) {
      this.selectedIds = v.map((item) => item.id);
    },
  },
};
</script>

<style lang="less" scoped>
/deep/ .table {
  width: calc(100vw - 336px);

}
</style>
